package cn.zyl.demo.common.boot.beans;

import java.lang.reflect.Method;
import java.util.Arrays;

/**
 * CommonApiBean类说明: 接口api信息实体
 *
 * @author wsz
 * @version v1.0
 * @date 2020-08-03
 */
public class CommonApiBean {
    /** 接口-请求路径*/
    private String url;
    /** 接口-请求方式*/
    private String urlMethod;
    /** 接口-请求参数类型*/
    private String params;
    /** 接口-所属类名*/
    private String className;
    /** 接口-方法名*/
    private String methodName;
    /** 接口-返回类型信息*/
    private String methodReturn;
    public CommonApiBean(String url,Method method,String urlMethod){
        this.url = url;
        this.className = method.getDeclaringClass().getName();
        this.methodName = method.getName();
        this.methodReturn = method.getGenericReturnType().getTypeName();
        this.params = method.getGenericParameterTypes().length > 0 ? Arrays.toString(method.getGenericParameterTypes()) : "";
        this.urlMethod = urlMethod;
    }
    public String getUrl() { return url; }
    public void setUrl(String url) { this.url = url; }
    public String getUrlMethod() { return urlMethod; }
    public void setUrlMethod(String urlMethod) { this.urlMethod = urlMethod; }
    public String getParams() { return params; }
    public void setParams(String params) { this.params = params; }
    public String getClassName() { return className; }
    public void setClassName(String className) { this.className = className; }
    public String getMethodName() { return methodName; }
    public void setMethodName(String methodName) { this.methodName = methodName; }
    public String getMethodReturn() { return methodReturn; }
    public void setMethodReturn(String methodReturn) { this.methodReturn = methodReturn; }

    @Override
    public String toString() {
        StringBuilder res = new StringBuilder("{");
        res.append(',').append("url").append('=').append('\'').append(url).append('\'');
        res.append(',').append("urlMethod").append('=').append('\'').append(urlMethod).append('\'');
        res.append(',').append("params").append('=').append('\'').append(params).append('\'');
        res.append(',').append("className").append('=').append('\'').append(className).append('\'');
        res.append(',').append("methodName").append('=').append('\'').append(methodName).append('\'');
        res.append(',').append("methodReturn").append('=').append('\'').append(methodReturn).append('\'');
        res.append('}');
        return res.toString();
    }
}
